package zhihuilan.common;


public class Response<T> {

    public static Response<?> EMPTY = Response.ok();

    private int code = 0;
    private String msg = "ok";
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Response() {
    }

    public Response(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Response(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Response<?> ok() {
        return new Response<>();
    }

    public static <T> Response<T> ok(T body) {
        return new Response<T>(0, "ok", body);
    }

    public static <T> Response<T> ok(String message, T body) {
        return new Response<T>(0, message, body);
    }

    public static <T> Response<T> error(int errorCode, String message) {
        return new Response<T>(errorCode, message);
    }

    public static <T> Response<T> error(int errorCode, String message, T body) {
        return new Response<T>(errorCode, message, body);
    }

    public Boolean hasError() {
        return this.code != 0;
    }

}